package com.jixiantubu.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gemptc.bean.Photo_Library;
import com.gemptc.bean.ReplyBean;
import com.gemptc.bean.TupianBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jixiantubu.entity.Post_InfoDaoimp;
import com.jixiantubu.entity.Reply_InfoDaoimp;
import com.jixiantubu.entity.TupianDaoimp;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;

/**
 * Servlet implementation class Tupian_servlet
 */
@WebServlet("/tupian_servlet")
public class Tupian_servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Tupian_servlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter printWriter = response.getWriter();
		String value = request.getParameter("key");
		TupianDaoimp tupian=new TupianDaoimp();
		Gson gson = new Gson();
		Type typeOfSrc = new TypeToken<List<ReplyBean>>() {
		}.getType();
		switch (value) {
		case "1":
			//论坛图片
			String pageNow=request.getParameter("page");
			List<TupianBean> postList =tupian.selectPostPhoto(Integer.parseInt(pageNow));
			String resultPost = gson.toJson(postList, typeOfSrc);
			printWriter.write(resultPost);
			break;
		case "2":
			//锦囊图片
			String pageNow1=request.getParameter("page");
			List<TupianBean> scienceList =tupian.selectSciencePhoto(Integer.parseInt(pageNow1));
			String resultScience = gson.toJson(scienceList, typeOfSrc);
			printWriter.write(resultScience);
			break;
		case "3":
			//游记图片
			String pageNow2=request.getParameter("page");
			List<TupianBean> travelsList =tupian.selectTravelsPhoto(Integer.parseInt(pageNow2));
			String resultTravels = gson.toJson(travelsList, typeOfSrc);
			printWriter.write(resultTravels);
			break;
		case "4":
			//论坛图片
			String pageNow3=request.getParameter("page");
			int user_id1=Integer.parseInt(request.getParameter("user_id"));
			List<TupianBean> wodeList =tupian.selectWodePhoto(user_id1,Integer.parseInt(pageNow3));
			String resultWode = gson.toJson(wodeList, typeOfSrc);
			printWriter.write(resultWode);
			break;
		default:
			break;
		}
	}

}
